package stack_queue

import "container/list"

func NewMyQueueS() *MyQueueS {
	return &MyQueueS{pushS: list.New(), popS: list.New()}
}

type MyQueueS struct {
	pushS *list.List
	popS  *list.List
}

func (s *MyQueueS) moveToPopS () {
	if s.popS.Len() == 0 {
		for s.pushS.Len() != 0 {
			s.popS.PushBack(s.pushS.Remove(s.pushS.Back()))
		}
	}
}

func (s *MyQueueS) Push (val int) {
	s.pushS.PushBack(val)
	s.moveToPopS()
}

func (s *MyQueueS) Pop () int {
	if s.popS.Len() == 0 && s.pushS.Len() == 0 {
		panic("stack was empty can't pop !!!")
	}
	s.moveToPopS()
	return s.popS.Remove(s.popS.Back()).(int)
}

func (s *MyQueueS) Top () int {
	if s.popS.Len() == 0 && s.pushS.Len() == 0 {
		panic("stack was empty !!!")
	}
	s.moveToPopS()
	return s.popS.Back().Value.(int)
}

func (s *MyQueueS) IsEmpty () bool {
	return s.popS.Len() == 0 && s.pushS.Len() == 0
}
